package com.zhengxyou.jetpackdemo.lifecycle_liveData_viewModel.lifecycle;

import android.util.Log;

import com.zhengxyou.jetpackdemo.lifecycle_liveData_viewModel.LifecycleLiveDataViewModelActivity;

import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;

/**
 * Lifecycle使用的2种方式之一：
 * 第一步：实现{@link LifecycleObserver}接口，并注解自己想要监听的生命周期
 * 第二步：通过getLifecycle().addObserver方法在组件那添加这个观察者,组件位观察所有者/被观察者
 *
 * @see LifecycleLiveDataViewModelActivity#addLifecycleObserver()
 */
public class MyConnectListener implements LifecycleObserver {
    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    public void onCreate() {
        Log.e("TAG", "onCreate");
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    public void onDestroy() {
        Log.e("TAG", "onDestroy");
    }
}
